/**
  * Created by wyc on 6/8/2017.
  *
  * Find the last but one element of a list.
  * Example:
  * scala> penultimate(List(1, 1, 2, 3, 5, 8))
  * res0: Int = 5
  */

package test

import ninenineqs._

class test_p02 extends UnitSpec{
  feature(this.getClass.toString) {
    val L1 = List(1, 1, 2, 3, 5, 8)
    val L2 = List[Int]()
    val L3 = List(4)

    val Ts:List[(List[Int]) => Int]=List(
      p02.penultimate_v1,
      p02.penultimate_v2
    )

    var v = 1
    for ( func <- Ts ) {
      scenario("penultimate_v" + v) {
        assert(func(L1) == 5)
        try {
          func(L2)
        }
        catch {
          case _ : NoSuchElementException => //Expected
        }
        try {
          func(L3)
        }
        catch {
          case _ : NoSuchElementException => //Expected
        }
      }
      v += 1
    }
  }
}
